<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <style>
        .hide {
            display: none;
        }

        .c1 {
            position: fixed;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            background: rgba(0, 0, 0, .5);
            z-index: 2;
        }

        .c2 {
            background-color: white;
            position: fixed;
            width: 300px;
            height: 200px;
            top: 50%;
            left: 50%;
            z-index: 3;
            margin-top: -150px;
            margin-left: -150px;
            padding-top: 2%;
            padding-left: 2%;
        }
    </style>
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            安灯响应
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">

        <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
            <ul class="aui-list aui-form-list">
                <!-- <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label" style="width: 200px">异常记录编码</div>
                        <div class="aui-list-item-input">
                            <input type="text" placeholder="异常记录编码" id="code" value="" onclick="getIdSelector();" />
                        </div>
                    </div>
                </li> -->
            </ul>
        </div>
        <div class="aui-btn aui-btn-info" style="width:45%;margin-left:4%;" onclick="swipeCard()">响应</div>
        <div class="aui-btn aui-btn-info" style="width:45%;margin-left:2%;" onclick="doSearch()">查询</div>

        <div
            style="background-color:white; width: 100%;margin-top:2%;overflow-x: auto;-webkit-overflow-scrolling:touch;">
            <table class="table" style='width:2440px;' id="table1">
                <tbody style="display:block">
                    <tr
                        style="text-align: center;background-color: #DCE9F2;color: #467aa7;font-size: 15px;font-weight: bold;">
                        <td algin='center' style='width: 40px;'></td>
                        <td algin='center' style='width:200px;'>任务主键</td>
                        <td algin='center' style='width:200px;'>节点状态</td>
                        <td algin='center' style='width:200px;'>异常记录编码</td>
                        <td algin='center' style='width:200px;'>异常类型编码</td>
                        <td algin='center' style='width:200px;'>异常类型名称</td>
                        <td algin='center' style='width:200px;'>异常内容编码</td>
                        <td algin='center' style='width:200px;'>异常内容名称</td>
                        <td algin='center' style='width:200px;'>异常描述</td>
                        <td algin='center' style='width:200px;'>工序编码</td>
                        <td algin='center' style='width:200px;'>物料编码</td>
                        <td algin='center' style='width:200px;'>发起人</td>
                        <td algin='center' style='width:200px;'>发起时间</td>
                        <td algin='center' style='width:200px;display:none;'>sysid</td>
                    </tr>
                </tbody>
            </table>
            <table class="table" style='width:2440px;' id="table">
                <tbody id="tbodyHtml" style="display: block;height: 500px;overflow-y: scroll;">
                </tbody>
            </table>
        </div>
        <div id="shade" class="c1 hide"></div>
        <div id="modal" class="c2 hide">
            <p style="margin-left: 10px;font-size: 0.8rem;font-weight: 500;color: #212121;text-align: center;">
                安灯响应</p>
            <ul class="aui-list aui-form-list" style="margin-top: 4%;">
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label" style="width: 200px;">扫描/录入卡号</div>
                        <div class="aui-list-item-input">
                            <input type="text" placeholder="扫描/录入卡号" id="empNo" />
                        </div>
                    </div>
                </li>
            </ul>
            <footer class="aui-bar aui-bar-tab" style="position: absolute;">
                <div class="aui-btn aui-btn-info" style="width:30%;margin-left:2%;" onclick="Hide()">取消
                </div>
                <div class="aui-btn aui-btn-info" style="width:30%;margin-left:10%;" onclick="responseSave()">确定</div>
            </footer>
        </div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    var lineCode = "";
    //初始化
    apiready = function () {
        lineCode = api.pageParam.lineCode;
        // $("#code").focus();
        // idSelector = "code";
        //获取当前日期
        // crateDate()
        doSearch();
    }

    function Hide() {
        document.getElementById('shade').classList.add('hide');
        document.getElementById('modal').classList.add('hide');
        document.getElementById('empNo').value = "";
    }

    //响应保存
    function responseSave(code, empNo) {
        //选中数据
        var check = $("input[type='checkbox']:checked"); //在table中找input下类型为checkbox属性为选中状态的数据
        var count = 0;
        var code = "";
        var nodeState = "";
        check.each(function () { //遍历
            var row = $(this).parent("td").parent("tr");
            code = row.find("[name='code']").html();
            nodeState = row.find("[name='nodeState']").html();
            count++;
        });

        console.log(nodeState)
        if (count != 1) {
            api.toast({
                msg: "请选择一条表格数据",
                duration: 3000
            });
            return;
        }

        if (nodeState != "待响应") {
            api.toast({
                msg: "请选择一条状态为【待响应】的数据!",
                duration: 3000
            });
            return;
        }

        var empNo = document.getElementById('empNo').value;
     


        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAssemblyAndonResponseNew";
        var data = {
            values: {
                exceptionCode: code,
                empNo: empNo,
                un: un,
            }
        };

        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        api.showProgress({
            title: '保存中...',
        });

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                api.hideProgress();
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //成功
                if (myobj.code == 0) {
                    api.toast({
                        msg: "保存成功!",
                        duration: 3000
                    });
                    Hide();
                    doSearch();
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                api.hideProgress();
                alert("网络连接超时!")
            }
        });
    }

    //获取当前日期
    function crateDate() {
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        $("#startTime").val(year + "-" + month + "-" + day + " 00:00:00");
        $("#endTime").val(year + "-" + month + "-" + day + " 23:59:00");
    }

    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }

    function swipeCard() {
        //选中数据
        var check = $("input[type='checkbox']:checked"); //在table中找input下类型为checkbox属性为选中状态的数据
        var count = 0;
        check.each(function () {
            count++;
        });

        //选中行不为1
        if (count != 1) {
            api.toast({
                msg: '请选择一条数据！',
                duration: 3000
            });
            return;
        }

        document.getElementById('shade').classList.remove('hide');
        document.getElementById('modal').classList.remove('hide');

        $("#empNo").focus();



        // var ids = "";
        // var taskId = "";
        // var exceptionTypeCode = "";
        // var exceptionTypeName = "";
        // var exceptionContentCode = "";
        // var exceptionContentName = "";
        // var exceptionRemark = "";
        // var opCode = "";
        // var mrlCode = "";
        // check.each(function () { //遍历
        //     var row = $(this).parent("td").parent("tr");
        //     var sysid = row.find("[name='sysid']").html();
        //     taskId = row.find("[name='taskId']").html();               // 获取任务ID
        //     exceptionTypeCode = row.find("[name='exceptionTypeCode']").html(); // 获取异常类型编码
        //     exceptionTypeName = row.find("[name='exceptionTypeName']").html(); // 获取异常类型名称
        //     exceptionContentCode = row.find("[name='exceptionContentCode']").html(); // 获取异常内容编码
        //     exceptionContentName = row.find("[name='exceptionContentName']").html(); // 获取异常内容名称
        //     exceptionRemark = row.find("[name='exceptionRemark']").html(); // 获取异常描述
        //     opCode = row.find("[name='opCode']").html();             // 获取工序编码
        //     mrlCode = row.find("[name='mrlCode']").html();           // 获取物料编码
        //     ids += "" + sysid + ","
        // });

        // if (ids) {
        //     ids = ids.substring(0, ids.length - 1);
        // }
        // console.log(ids)

        // api.openWin({
        //     name: 'andon_response_detail',
        //     url: 'andon_response_detail.html',
        //     pageParam: {
        //         name: "andon_response",
        //         id: ids,
        //         taskId: taskId,
        //         exceptionTypeCode: exceptionTypeCode,
        //         exceptionTypeName: exceptionTypeName,
        //         exceptionContentCode: exceptionContentCode,
        //         exceptionContentName: exceptionContentName,
        //         exceptionRemark: exceptionRemark,
        //         opCode: opCode,
        //         mrlCode: mrlCode,
        //     }
        // });
    }

    function showTime() {
        var moduleTimer = api.require('moduleTimer');
        moduleTimer.showTimer({
            startTime: '2000-01-01 00:00:00',//可选择的起始时间
            endTime: '2099-12-31 23:59:59',//可选择的结束时间
            timeFormat: 'yyyy-MM-dd HH:mm:ss',//返回的时间格式，如果不传默认是yyyy-MM-dd HH:mm:ss
            selColor: '#079962'//选中的颜色值
        }, function (ret, err) {
            var actualBeginDate = ret;
            var text = document.getElementById("startTime");
            text.value = actualBeginDate;
        });
    }

    function showTime2() {
        var moduleTimer = api.require('moduleTimer');
        moduleTimer.showTimer({
            startTime: '2000-01-01 00:00:00',//可选择的起始时间
            endTime: '2099-12-31 23:59:59',//可选择的结束时间
            timeFormat: 'yyyy-MM-dd HH:mm:ss',//返回的时间格式，如果不传默认是yyyy-MM-dd HH:mm:ss
            selColor: '#079962'//选中的颜色值
        }, function (ret, err) {
            var actualBeginDate = ret;
            var text = document.getElementById("endTime");
            text.value = actualBeginDate;
        });
    }

    //查询
    function doSearch() {
        // var code = $("#code").val();
        // var startTime = $("#startTime").val();
        // var endTime = $("#endTime").val();
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAndonResponseList";
        var data = {
            values: {
                // key: code,
                // startTime: startTime,
                // endTime: endTime,
                un: un,
                lineCode: lineCode,
                state: '0',
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //返回成功
                if (myobj.code == "0") {
                    var list = eval(myobj.list);
                    var html = "";
                    for (var i = 0; i < list.length; i++) {
                        html += "<tr style='text-align: center;color: black;font-size: 12px;background-color: #F5F5F5;'>";
                        html += "<td style='width:40px;'><input name='sub' type='checkbox' /></td>";
                        html += "<td name='taskId'style='width:200px;'>" + list[i].taskId + "</td>";
                        html += "<td name='nodeState' style='width:200px;'>" + list[i].nodeStatus + "</td>";
                        html += "<td name='code' style='width:200px;'>" + list[i].code + "</td>";
                        html += "<td name='exceptionTypeCode' style='width:200px;'>" + list[i].exceptionTypeCode + "</td>";
                        html += "<td name='exceptionTypeName' style='width:200px;'>" + list[i].exceptionTypeName + "</td>";
                        html += "<td name='exceptionContentCode' style='width:200px;'>" + list[i].exceptionContentCode + "</td>";
                        html += "<td name='exceptionContentName' style='width:200px;'>" + list[i].exceptionContentName + "</td>";
                        html += "<td name='exceptionRemark' style='width:200px;'>" + list[i].exceptionRemark + "</td>";
                        html += "<td name='opCode' style='width:200px;'>" + list[i].opCode + "</td>";
                        html += "<td name='mrlCode' style='width:200px;'>" + list[i].mrlCode + "</td>";
                        html += "<td name='launchId' style='width:200px;'>" + list[i].launchId + "</td>";
                        html += "<td name='launchDate' style='width:200px;'>" + list[i].launchDate + "</td>";
                        html += "<td name='sysid'style='width:200px;display:none' >" + list[i].sysid + "</td>";
                        html += "</tr>";
                    }
                    $api.html($api.byId("tbodyHtml"), html);

                    //失败
                } else if (myobj.code == "1") {

                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }
    function dealSuccess() {
        doSearch()
    }
    //订单返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>